<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            div {
                width: 200px;
                height: 200px;
                background: red;
            }
        </style>
    </head>
    <body>
        <div></div>
        <h1>111</h1>
        <script>
            let div = document.querySelector('div');
            let h1 = document.getElementsByTagName('h1');
            div.onclick = function () {
                console.log('111');
                alert('1111');
            };
            h1.onclick = function () {
                console.log('222');
                alert('2222');
            };
        </script>
    </body>
</html>
